from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

options = webdriver.ChromeOptions()  # 创建谷歌浏览器的options对象来接收浏览器的相关设置

options.add_argument('--start-maximized')  # 最大化窗口
options.add_argument('--incognito')  # 无痕浏览
options.add_argument('--disable-extensions')  # 禁用浏览器的扩展程序,避免干扰网站的打开
options.add_experimental_option("detach", True)  # 禁止浏览器自动关闭
options.add_experimental_option('excludeSwitches', ['enable-automation'])
options.add_experimental_option('useAutomationExtension', False)

options.add_argument('--headless')
options.add_argument('user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"',)
options.add_argument('--disable-gpu')

driver = webdriver.Chrome(options)  # 创建谷歌浏览器驱动对象

driver.execute_cdp_cmd('Page.addScriptToEvaluateOnNewDocument', {
    'source':'''
    Object.defineProperty(navigator, 'webdriver',{get:() => false})
    '''
})

driver.get('https://antispider1.scrape.center/page/1')

wait = WebDriverWait(driver, 6) #设置等待时间

# titles = driver.find_elements(By.CLASS_NAME,'m-b-sm')   #这里你能直接用find_elements直接请求  因为网页需要通过js加载渲染
# titles = wait.until(EC.presence_of_all_elements_located((By.CLASS_NAME, 'm-b-sm')))

driver.quit()

